<template>
    <example :template-code="templateString">
        <template #describe>
            <t :id="`${$t('仅允许选择叶子节点')}`">{{ $t('仅允许选择叶子节点') }}</t>
            <li>
                配置<span class="s-code">isLeafOnly</span>为<span class="s-code">true</span>，则可以控制树选择器只允许选择<span style="color:#000;font-weight: 600;">叶子节点</span>
            </li>
            <li>
                配置<span class="s-code">required</span>为<span class="s-code">true</span>，可以控制树选择器必须选择节点才可以点击确定
            </li>
        </template>
        <div style="width: 300px;">
            <sib-item v-model="value" :props="props"></sib-item>
        </div>
        <p style="color: #666;">当前选择的是：{{ value && value.length ? value : '--' }}</p>
    </example>
</template>

<script>
import { ref, reactive } from 'vue';

export default {
    setup() {
        const treeData = [
            {
                id: 1,
                name: '一级 1',
                children: [
                    {
                        id: 4,
                        name: '二级 1-1',
                        children: [
                            {
                                id: 9,
                                name: '三级 1-1-1',
                            },
                            {
                                id: 10,
                                name: '三级 1-1-2',
                            },
                        ],
                    },
                ],
            },
            {
                id: 2,
                name: '一级 2',
                children: [
                    {
                        id: 5,
                        name: '二级 2-1',
                    },
                    {
                        id: 6,
                        name: '二级 2-2',
                    },
                ],
            },
        ];
        const value = ref(null);
        const props = reactive({
            type: 'tree',
            data: treeData,
            required: true,
            isLeafOnly: true,
        });

        return {
            props,
            value,
            templateString: `<template>
    <sib-item v-model="value" :props="props"></sib-item>
    <p>当前选择的是：{{ value && value.length ? value : '--' }}</p>
</template>

<script>
import { ref, reactive } from 'vue';

export default {
    setup() {
        const treeData = [
            {
                id: 1,
                name: '一级 1',
                children: [
                    {
                        id: 4,
                        name: '二级 1-1',
                        children: [
                            {
                                id: 9,
                                name: '三级 1-1-1',
                            },
                            {
                                id: 10,
                                name: '三级 1-1-2',
                            },
                        ],
                    },
                ],
            },
            {
                id: 2,
                name: '一级 2',
                children: [
                    {
                        id: 5,
                        name: '二级 2-1',
                    },
                    {
                        id: 6,
                        name: '二级 2-2',
                    },
                ],
            },
        ];
        const value = ref(null);
        const props = reactive({
            type: 'tree',
            data: treeData,
            required: true,
            isLeafOnly: true,
        });

        return { props, value };
    },
};
<\/script>`,
        };
    },
};
</script>
